<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: class.collect_params.php 414 2014-01-18 16:21:56Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 414 $
* 	zuletzt geändert von:	$Author: siekiera $
* 	Datum:					$Date: 2014-01-18 16:21:56 +0000 (Sat, 18 Jan 2014) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

class collect_params {
	public $parameters = array();
	public $listName;
	public $listData;
	
	public $cols;

	function __construct() {}

	function __destruct() {}

	public function navLinks($createLinks) {
		
		if($createLinks) {
			global $current_category_id;
			
			$get_view = $_GET['view_as'];
			$get_per_site = (int)$_GET['per_site'];
			
			if(!empty($current_category_id) && isset($_SESSION['view_as'][$this->page_style.'_'.$current_category_id])) {
				$session_site = $this->page_style.'_'.$current_category_id;
				$session_site_view_as = $_SESSION['view_as'][$this->page_style.'_'.$current_category_id]['style'];
			} elseif(isset($_SESSION['view_as'][$this->page_style])) {
				$session_site = $this->page_style;
				$session_site_view_as = $_SESSION['view_as'][$this->page_style]['style'];
			}

			if(!empty($get_view)) {
				$this->listData = $this->getListData($this->page_style.'_'.$get_view);
				$this->listName = $get_view;
				$this->page_name = $this->page_style.'_'.$get_view;
				
				if(!empty($current_category_id))
					$_SESSION['view_as'][$this->page_style.'_'.$current_category_id]['style'] = $get_view;
				else
					$_SESSION['view_as'][$this->page_style]['style'] = $get_view;		

			} elseif(!empty($session_site)) {
				if(!empty($current_category_id)) {
					$clean_name = str_replace('_'.$current_category_id, '', $session_site);
					$this->listData = $this->getListData($clean_name.'_'.$session_site_view_as);
					$this->listName = $session_site_view_as;
					$this->page_name = $clean_name.'_'.$session_site_view_as;
					
				} else {
					$this->listData = $this->getListData($session_site.'_'.$session_site_view_as);
					$this->listName = $session_site_view_as;
					$this->page_name = $session_site.'_'.$session_site_view_as;
				}

			} else {
				if(!empty($current_category_id)) {
					$get_list = $this->db->db_query("SELECT category_default_list FROM ".TABLE_CATEGORIES." WHERE categories_id = '".$current_category_id."' ");
          if ($this->page_style != '')
            $get_list->fields['category_default_list'] = $this->page_style.'_grid';
					if(!empty($get_list->fields['category_default_list'])) {
						
						$name = explode('_', $get_list->fields['category_default_list']);
						$plain = array_reverse($name);
						$this->listName = $plain[0];
						$this->page_name = str_replace('_'.$plain[0], '', $get_list->fields['category_default_list']);
						$this->listData = $this->getListData($get_list->fields['category_default_list']);
						$_SESSION['view_as'][$this->page_name.'_'.$current_category_id]['style'] = $plain[0];
						
					} else {
						$this->listName = 'grid';
						$this->page_name = $this->page_style.'_grid';
						$this->listData = $this->getListData($this->page_style.'_grid');
						$_SESSION['view_as'][$this->page_style.'_'.$current_category_id]['style'] = 'grid';
					}
						
				} else {
					$this->listName = 'grid';
					$this->page_name = $this->page_style.'_grid';
					$this->listData = $this->getListData($this->page_style.'_grid');
					$_SESSION['view_as'][$this->page_style]['style'] = 'grid';
				}
			}
			
			if(!empty($get_per_site)) {
				$this->perPage = $get_per_site;
				$_SESSION['per_site'] = $get_per_site;
				$this->getCols($get_per_site);

			} elseif(isset($_SESSION['per_site'])) {
				$this->perPage = $_SESSION['per_site'];
				$this->getCols($_SESSION['per_site']);
				
			} elseif(!isset($_SESSION['per_site']) || !isset($get_per_site) && !empty($this->listName)) {
				$getCols = $this->db->db_query("SELECT col FROM ".TABLE_PRODUCTS_LISTINGS." WHERE list_name ='".$this->page_name."'");
				switch($getCols->fields['col']) {
					case '3' : $this->perPage  = 18; $_SESSION['per_site'] = 18; $this->cols = 3; break;
					case '4' : $this->perPage  = 24; $_SESSION['per_site'] = 24; $this->cols = 4; break;
					default : $this->perPage  = 18; $_SESSION['per_site'] = 18; $this->cols = 3; break;
				}
				
			} else {
				$this->perPage = 18;
				$this->cols = 3;
				$_SESSION['per_site'] = 18;
			}
		}
	}
	
	function getListData($list_name) {
		$options = $this->db->db_query("SELECT 
											list_name, 
											col, 
											p_img, 
											p_name, 
											p_price, 
											b_details, 
											b_order, 
											b_wishlist, 
											p_reviews, 
											p_stockimg, 
											p_vpe, 
											p_model,
											p_isbn, 
											p_manu_img, 
											p_manu_name, 
											p_short_desc, 
											p_short_desc_lenght, 
											p_long_desc, 
											p_long_desc_lenght, 
											list_type,
											list_file,
											box_count,
											box_effect,
											effect_direction
										FROM 
											".TABLE_PRODUCTS_LISTINGS." 
										WHERE 
											list_name = '".$list_name."' ");
		if($options->_numOfRows)
			return $options->fields;
		else
			return false;
	}
	
	function paramOutput() {
		return $this->parameters;
	}
	
	function getCols($per_site) {
		switch($per_site) {
			case '9':
			case '18':
			case '27':
			case '45':
			case '81':
				$this->cols = 3;
				break;
				
			case '12':
			case '24':
			case '60':
			case '84':
			case '96':
				$this->cols = 4;
				break;
				
			default:
				$this->cols = 2;
				break;
		}
		
	}
}
?>